package cn.doctorpda.meeting.presenter;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import cn.doctorpda.meeting.bean.Entity;
import cn.doctorpda.meeting.bean.Info;
import cn.doctorpda.meeting.bean.Msg;
import cn.doctorpda.meeting.config.AppConfig;
import cn.doctorpda.meeting.config.NetConfig;
import cn.doctorpda.meeting.model.BaseModel;
import cn.doctorpda.meeting.model.IBaseModel;
import cn.doctorpda.meeting.okhttp.callback.ResultCallback;
import cn.doctorpda.meeting.okhttp.callback.StringCallback;
import cn.doctorpda.meeting.utils.AESUtil;
import cn.doctorpda.meeting.utils.GsonUtil;
import cn.doctorpda.meeting.utils.L;
import cn.doctorpda.meeting.view.callbackview.IBaseView;
import okhttp3.Call;

/**
 * Created by huangjinlong on 2016/5/13.
 */
public class BasePresenter {
    private IBaseModel baseModel;
    private IBaseView baseView;

    public BasePresenter(IBaseView baseView) {
        this.baseView = baseView;
        baseModel = new BaseModel();
    }

    public void getDatas(){
        baseModel.getNetWorkStringData(NetConfig.GET_HOME_INFO, new ResultCallback() {
            @Override
            public void onError(Call call, Exception e) {

            }

            @Override
            public void onResponse(Msg response) {
                String data = AESUtil.decrypt(response.getData(), AppConfig.AES_KEY);
                Info info = GsonUtil.fromJson(data, Info.class);
            }
        });
    }

    public void getData() {
        baseModel.getNetWorkStringData("http://115.28.162.149/api/dg_fidlist.php", new StringCallback() {
            @Override
            public void onError(Call call, Exception e) {

            }

            @Override
            public void onResponse(String response) {
                Gson gson = new Gson();
//
                Entity<Info> data = GsonUtil.fromEntity(response, new TypeToken<Entity<Info>>(){});
//                L.d(String.valueOf(data.getTarget().get(0).getId()));
            }
        });
    }

    public void postData(){
        baseModel.postNetWorkStringData("http://115.28.162.149/work_api/1.0/1.0.30/get_work_list.php", new StringCallback() {
            @Override
            public void onError(Call call, Exception e) {

            }

            @Override
            public void onResponse(String response) {
                Gson gson = new Gson();
                Entity<Info> data = gson.fromJson(response, Entity.class);
                L.d(data.getTarget().get(0).getId());
            }
        }, "370200", "1");
    }
}
